package com.yxq.mdt.app.modules.search.prestener;


import com.yxq.mdt.app.base.BasePresenter;
import com.yxq.mdt.app.modules.search.bean.SearchBean;
import com.yxq.mdt.app.modules.search.bean.SearchGroupBean;
import com.yxq.mdt.app.modules.search.bean.SearchTopicBean;
import com.yxq.mdt.app.modules.search.bean.SearchUserBean;
import com.yxq.mdt.app.modules.search.model.SearchModel;
import com.yxq.mdt.app.net.ApiModel;

public class SearchPresenter extends BasePresenter<ISearchContract.View, SearchModel> implements ISearchContract.Presenter {

    public SearchPresenter(ISearchContract.View view, SearchModel model) {
        super(view, model);
    }

    /**
     * 搜索
     *
     * @param keyword    关键字
     * @param defaultCat 搜索类型
     *                   {
     *                   "id": 0,
     *                   "name": "默认",
     *                   "key": "m",
     *                   "url": "/pages/goods/goods?id="
     *                   }
     */
    @Override
    public void search(String keyword, String defaultCat) {

        mBaseModel.search(keyword, defaultCat, new ApiModel.CommonCallback<SearchBean>() {
            @Override
            public void onSuccess(SearchBean SearchBean) {
                mRootView.onLoadSuccess(SearchBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadFailed(errMsg);
            }
        });
    }

    public void searchGsUser(String keyword, int pageNum, int pageSize) {

        mBaseModel.searchGsUser(keyword, pageNum, pageSize, new ApiModel.CommonCallback<SearchUserBean>() {
            @Override
            public void onSuccess(SearchUserBean SearchBean) {
                mRootView.onLoadUserSuccess(SearchBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadUserFailed(errMsg);
            }
        });
    }

    public void searchGroup(String keyword, int pageNum, int pageSize) {

        mBaseModel.searchGroup(keyword, pageNum, pageSize, new ApiModel.CommonCallback<SearchGroupBean>() {
            @Override
            public void onSuccess(SearchGroupBean SearchBean) {
                mRootView.onLoadGroupSuccess(SearchBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadGroupFailed(errMsg);
            }
        });
    }

    public void searchTopic(String keyword, int pageNum, int pageSize) {

        mBaseModel.searchTopic(keyword, pageNum, pageSize, new ApiModel.CommonCallback<SearchTopicBean>() {
            @Override
            public void onSuccess(SearchTopicBean SearchBean) {
                mRootView.onLoadTopicSuccess(SearchBean);
            }

            @Override
            public void onError(String errMsg) {
                mRootView.onLoadTopicFailed(errMsg);
            }
        });
    }
}
